<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2019 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
declare (strict_types = 1);

namespace app\api\middleware;

use Closure;
use think\Config;
use think\Request;
use think\Response;

use \app\api\service\Token;

class Auth {
  public function handle($request, Closure $next) {
    $token = $request->header('X-Token');
    $result = Token::verify($token);
    if(!$result) {
      return json([
       'code' => config('status.error'),
       'message' => '无访问权限',
       'data' => [] 
      ], 401);
    }
    return $next($request);
  }
}
